package com.nirvana.utils;


import com.nirvana.config.PluginConfig;
import com.nirvana.convert.CamelCaseConverter;
import com.nirvana.data.DbFieldInfo;

import java.util.List;


public class CommonUtil {
    public static String ExchangeEntityName(String entityName) {
        return entityName.substring(0, 1).toUpperCase() + entityName.substring(1);
    }

    public static String toLowerName(String entityName) {
        return CamelCaseConverter.toCamelCase(entityName, true);
    }

    public static String toUpperName(String entityName) {
        return CamelCaseConverter.toCamelCase(entityName, false);
    }

    public static String CreateInterfaceName(String entityName) {
        return "I" + entityName + "Dao";
    }

    public static String CreateImplName(String entityName) {
        return entityName + "DaoImpl";
    }

    public static String CreateFactoryName(String entityName) {
        return "Player" + entityName + "Fcatory";
    }

    public static String CreateBusinessName(String entityName) {
        return entityName + "Bussiness";
    }

    public static String CreateEntityName(String entityName) {
        return entityName;
    }

    public static String CreateEntityParameterName(String entityName) {
        return toLowerName(entityName);
    }

    public static String CreateEntityPluralParaName(String entityName) {
        return toLowerName(entityName) + "s";
    }

    public static String generateDaoEntityPackage() {
        return PluginConfig.getInstance().getEntityPackage();
    }

    public static String createPrimaryMethodName(List<DbFieldInfo> primaryFieldInfos) {
        List<String> list = primaryFieldInfos.stream().map(info -> CamelCaseConverter.toCamelCase(info.getColumnName(), false)).toList();
        return String.join("And", list);
    }

    public static String createPrimaryMethodParams(List<DbFieldInfo> primaryFieldInfos) {
        List<String> list = primaryFieldInfos.stream().map(info -> "String " + CamelCaseConverter.toCamelCase(info.getColumnName(), true)).toList();
        return String.join(", ", list);
    }

    public static String createPrimaryMethodInvokeParams(List<DbFieldInfo> primaryFieldInfos) {
        List<String> list = primaryFieldInfos.stream().map(info -> CamelCaseConverter.toCamelCase(info.getColumnName(), true)).toList();
        return String.join(", ", list);
    }
}
